home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / select-to-brush.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  4.1 KB  |  129 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Selection-to-brush 
  4. ; Copyright (c) 1997 Adrian Likins
  5. ; aklikins@eos.ncsu.edu
  6. ;
  7. ; Takes the current selection, saves it as a brush, and makes it the
  8. ; active brush..
  9. ;
  10. ;       Parts of this script from Sven Neuman's Drop-Shadow and 
  11. ;       Seth Burgess's mkbrush scripts.
  12. ;
  13. ; This program is free software; you can redistribute it and/or modify
  14. ; it under the terms of the GNU General Public License as published by
  15. ; the Free Software Foundation; either version 2 of the License, or
  16. ; (at your option) any later version.
  17. ; This program is distributed in the hope that it will be useful,
  18. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. ; GNU General Public License for more details.
  21. ; You should have received a copy of the GNU General Public License
  22. ; along with this program; if not, write to the Free Software
  23. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.  
  26. (define (script-fu-selection-to-brush image
  27.                                       drawable
  28.                                       name
  29.                                       filename
  30.                                       spacing)
  31.   (let* ((type (car (gimp-drawable-type-with-alpha drawable)))
  32.      (selection-bounds (gimp-selection-bounds image))
  33.      (select-offset-x  (cadr selection-bounds))
  34.      (select-offset-y  (caddr selection-bounds))
  35.      (selection-width  (- (cadr (cddr selection-bounds))  select-offset-x))
  36.      (selection-height (- (caddr (cddr selection-bounds)) select-offset-y)))
  37.  
  38.     (gimp-context-push)
  39.  
  40.     (gimp-image-undo-disable image)
  41.     
  42.     (if (= (car (gimp-selection-is-empty image)) TRUE)
  43.     (begin
  44.       (gimp-selection-layer-alpha drawable)
  45.       (set! from-selection FALSE))
  46.     (begin
  47.       (set! from-selection TRUE)
  48.       (set! active-selection (car (gimp-selection-save image)))))
  49.  
  50.     (gimp-edit-copy drawable)
  51.  
  52.     (set! brush_draw_type
  53.           (if (= type GRAYA-IMAGE)
  54.               GRAY-IMAGE
  55.               RGBA-IMAGE))
  56.  
  57.     (set! brush_image_type
  58.           (if (= type GRAYA-IMAGE)
  59.               GRAY
  60.               RGB))
  61.  
  62.     (set! brush-image (car (gimp-image-new selection-width
  63.                                            selection-height
  64.                                            brush_image_type)))
  65.  
  66.     (set! brush-draw
  67.           (car (gimp-layer-new brush-image
  68.                                selection-width
  69.                                selection-height
  70.                                brush_draw_type
  71.                                "Brush"
  72.                                100
  73.                                NORMAL-MODE)))
  74.  
  75.     (gimp-image-add-layer brush-image brush-draw 0)
  76.  
  77.     (gimp-selection-none brush-image)
  78.  
  79.     (if (= type GRAYA-IMAGE)
  80.         (begin 
  81.           (gimp-context-set-background '(255 255 255))
  82.           (gimp-drawable-fill brush-draw BACKGROUND-FILL))
  83.         (gimp-drawable-fill brush-draw TRANSPARENT-FILL))
  84.  
  85.     (let ((floating-sel (car (gimp-edit-paste brush-draw FALSE))))
  86.       (gimp-floating-sel-anchor floating-sel))
  87.  
  88.     (set! filename2 (string-append gimp-directory
  89.                    "/brushes/"
  90.                    filename
  91.                    (number->string image)
  92.                    ".gbr"))
  93.  
  94.     (file-gbr-save 1 brush-image brush-draw filename2 "" spacing name)
  95.  
  96.     (if (= from-selection TRUE)
  97.     (begin
  98.       (gimp-selection-load active-selection)
  99.       (gimp-image-remove-channel image active-selection)))
  100.  
  101.     (gimp-image-undo-enable image)
  102.     (gimp-image-set-active-layer image drawable)
  103.     (gimp-image-delete brush-image)
  104.     (gimp-displays-flush)
  105.  
  106.     (gimp-context-pop)
  107.  
  108.     (gimp-brushes-refresh)
  109.     (gimp-context-set-brush name)))
  110.  
  111. (script-fu-register "script-fu-selection-to-brush"
  112.             _"To _Brush..."
  113.             "Convert a selection to a brush"
  114.             "Adrian Likins <adrian@gimp.org>"
  115.             "Adrian Likins"
  116.             "10/07/97"
  117.             "RGB* GRAY*"
  118.             SF-IMAGE       "Image"       0
  119.             SF-DRAWABLE    "Drawable"    0
  120.             SF-STRING     _"Brush name"  "My Brush"
  121.             SF-STRING     _"File name"   "mybrush"
  122.             SF-ADJUSTMENT _"Spacing"     '(25 0 1000 1 1 1 0))
  123.  
  124. (script-fu-menu-register "script-fu-selection-to-brush"
  125.              _"<Image>/Script-Fu/Selection")
  126.